﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SpeakupUI
{
    class WaitDialog: Window 
    {
        Button CancelButton;
        Label Label;
        ProgressBar ProgressBar;

        public WaitDialog()
        {
            Title = "Speakup web-server communication";

            SizeToContent = SizeToContent.WidthAndHeight;
            Background = Brushes.WhiteSmoke;
            ResizeMode = ResizeMode.NoResize;
            
            StackPanel panel = new StackPanel();
            panel.Margin = new Thickness(10);

            ProgressBar = new ProgressBar();
            ProgressBar.IsIndeterminate = true;
            ProgressBar.Height = 20;
            ProgressBar.Foreground = Brushes.Orange;

            Label = new Label();
            Label.HorizontalAlignment = HorizontalAlignment.Center;
            Label.Content = "Sending request to web-server...";
            Label.Margin = new Thickness(10);

            CancelButton = new Button();
            CancelButton.Content = "Cancel";
            CancelButton.Margin = new Thickness(10);
            CancelButton.Padding = new Thickness(3);
            CancelButton.HorizontalAlignment = HorizontalAlignment.Center;
            CancelButton.Click += delegate { this.Close(); };

            panel.Children.Add(Label);
            panel.Children.Add(ProgressBar);
            panel.Children.Add(CancelButton);

            Content = panel;
        }

        public bool AllowClose = true;

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            Label.Content = "Cancelling web-request...";
            CancelButton.IsEnabled = false;
            e.Cancel = !AllowClose; ProgressBar.Foreground = Brushes.Red;
            
            e.Cancel = !AllowClose;
            base.OnClosing(e);
        }
    }
}
